#include <globals.au3>

Func reo_traycbevent($num)
  local $clip = $cbb[$num-1]
  local $a
  $clicked = 1

  if ClipGet() == $clip then return

  if $num < $traytotalnum then
    for $a=$num to $traytotalnum-1
  		TrayItemSetText($traycb[$a-1],TrayItemGetText($traycb[$a]))
  		$cbb[$a-1] = $cbb[$a]
  	next
  EndIf
  TrayItemSetState($traycb[$num-1],$TRAY_UNCHECKED)
  TrayItemSetState($traycb[$traytotalnum-1],$TRAY_CHECKED)
  
  if ($clip<>"") then
    ClipPut($clip)
  EndIf
EndFunc

Func reo_entry_add()
  SaveClipToFile($cb)
  
  If ($traytotalnum < $clip_entries_size) and ($clicked == 0) Then
    $traytotalnum += 1
    $traycb[$traytotalnum-1] = TrayCreateItem("<empty>",-1,$traytotalnum,1)
    TrayItemSetOnEvent($traycb[$traytotalnum-1],"traycbevent"&$traytotalnum)
    $cbb[$traytotalnum-1] = $cb
    If ($traytotalnum > 1) Then
      TrayItemSetState($traycb[$traytotalnum-2],$TRAY_UNCHECKED)
      TrayItemSetState($traycb[$traytotalnum-1],$TRAY_CHECKED)
    EndIf
    
  ElseIf $clicked == 1 Then
    $clicked = 0
  Else
    for $a=0 to $traytotalnum-2
          TrayItemSetText($traycb[$a],TrayItemGetText($traycb[$a+1]))
          $cbb[$a] = $cbb[$a+1]
      next
      $cbb[$traytotalnum-1] = $cb
  EndIf
  
  TrayItemSetText($traycb[$traytotalnum-1],shorten($cb))
  
  $lc = $cb
   
EndFunc
